package com.example.backend.repository;

import com.example.backend.domain.entity.TicketCategory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface TicketCategoryRepository extends JpaRepository<TicketCategory, Long> {
    
    Optional<TicketCategory> findByCategoryCode(String categoryCode);
    
    List<TicketCategory> findByIsActiveTrueOrderBySortOrderAsc();
    
    List<TicketCategory> findByParentIdIsNullAndIsActiveTrueOrderBySortOrderAsc();
    
    List<TicketCategory> findByParentIdAndIsActiveTrueOrderBySortOrderAsc(Long parentId);
    
    @Query("SELECT c FROM TicketCategory c WHERE c.isActive = true AND (c.categoryName LIKE %:keyword% OR c.description LIKE %:keyword%)")
    List<TicketCategory> searchByKeyword(String keyword);
}
